package com.ufaud.ais.sys.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import com.ufaud.ais.pub.entity.BaseEntity;

/**
 * 
 * @author Chenjd 2010-6-25
 * 
 */
@Entity
@Table(name = "menu_item")
public class MenuItem extends BaseEntity {

	/**
	 * DIR_TYPE = "dir"
	 */
	public static final String DIR_TYPE = "dir";
	/**
	 * URL_TYPE = "url"
	 */
	public static final String URL_TYPE = "url";

	@Id
	@GeneratedValue
	@Column(name = "menu_item_id")
	private Long menuItemId;

	@Column(name = "menu_item_code")
	private String menuItemCode;

	@Column(name = "menu_item_name")
	private String menuItemName;

	@Column(name = "menu_item_type")
	private String menuItemType;

	@OneToMany(fetch = FetchType.EAGER, mappedBy = "superMenuItem", targetEntity = MenuItem.class)
	@Cascade(value = { CascadeType.PERSIST, CascadeType.DELETE, CascadeType.SAVE_UPDATE })
	private Set<MenuItem> menuItemSet = new HashSet<MenuItem>();

	@ManyToOne(fetch = FetchType.EAGER, targetEntity = MenuItem.class)
	@JoinColumn(name = "super_menu_item_id")
	private MenuItem superMenuItem;

	@Column(name = "menu_item_target")
	private String menuItemTarget;

	@Column(name = "menu_item_ico")
	private String menuItemIco;

	public Long getMenuItemId() {
		return menuItemId;
	}

	public void setMenuItemId(Long menuItemId) {
		this.menuItemId = menuItemId;
	}

	public String getMenuItemCode() {
		return menuItemCode;
	}

	public void setMenuItemCode(String menuItemCode) {
		this.menuItemCode = menuItemCode;
	}

	public String getMenuItemName() {
		return menuItemName;
	}

	public void setMenuItemName(String menuItemName) {
		this.menuItemName = menuItemName;
	}

	public String getMenuItemType() {
		return menuItemType;
	}

	public void setMenuItemType(String menuItemType) {
		this.menuItemType = menuItemType;
	}

	public Set<MenuItem> getMenuItemSet() {
		return menuItemSet;
	}

	public void setMenuItemSet(Set<MenuItem> menuItemSet) {
		this.menuItemSet = menuItemSet;
	}

	public MenuItem getSuperMenuItem() {
		return superMenuItem;
	}

	public void setSuperMenuItem(MenuItem superMenuItem) {
		this.superMenuItem = superMenuItem;
	}

	public String getMenuItemTarget() {
		return menuItemTarget;
	}

	public void setMenuItemTarget(String menuItemTarget) {
		this.menuItemTarget = menuItemTarget;
	}

	public String getMenuItemIco() {
		return menuItemIco;
	}

	public void setMenuItemIco(String menuItemIco) {
		this.menuItemIco = menuItemIco;
	}

	public boolean addMenuItem(MenuItem menuItem) {
		return menuItemSet.add(menuItem);
	}

	public boolean removeMenuItem(MenuItem menuItem) {
		return menuItemSet.remove(menuItem);
	}

}
